package com.ablog.controller;

import com.ablog.model.Article;
import com.ablog.service.ArticleService;
import com.ablog.util.ResultUtil;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Article)表控制层
 *
 * @author mopeiwen
 * @since 2020-07-22 13:17:39
 */
@RestController
@RequestMapping("/article")
public class ArticleController {
    /**
     * 服务对象
     */
    @Resource
    private ArticleService articleService;
    
     /**
     * Select list ResultUtil.
     *
     * @param article
     * @return the ResultUtil
     */
    @GetMapping(value = "/query-all")
    public ResultUtil queryAll(Article article) {
        return ResultUtil.ok("查询列表", articleService.queryAll(article));
    }
    
    /**
     * 分页查询 按对象
     * @param article
     * @return
     */
    @GetMapping(value = "/query-all-page")
    public ResultUtil queryAllPage(Article article,int pagesize,int pagenum) {
        return ResultUtil.ok("查询列表", articleService.queryAll(article, pagesize, pagenum));
    }
    
    /**
     * 分页查询 按内容或标题
     * @param value
     * @return
     */
    @GetMapping(value = "/query-all-val")
    public ResultUtil queryAllVal(String value,int pagesize,int pagenum) {
        return ResultUtil.ok("查询列表", articleService.queryAll(value, pagesize, pagenum));
    }
    
    /**
     * 分页查询 按时间
     * @param starttime
     * @param endtime
     * @return
     */
    @GetMapping(value = "/query-all-time")
    public ResultUtil queryAllTime(String starttime,String endtime,int pagesize,int pagenum) {
        return ResultUtil.ok("查询列表", articleService.queryAllByTime(starttime, endtime, pagesize, pagenum));
    }
    
    /**
     * Select obj ResultUtil.
     *
     * @param id
     * @return the ResultUtil
     */
    @GetMapping(value = "/query")
    public ResultUtil queryById(@RequestParam("id") String id) {
        return ResultUtil.ok("查询详情", articleService.queryById(id));
    }
    
    /**
     * Insert obj ResultUtil.
     *
     * @param article
     * @return the ResultUtil
     */
    @PostMapping(value = "/add")
    public ResultUtil add(@RequestBody Article article) {
        return ResultUtil.ok("添加成功", articleService.add(article));
    }
    
    /**
     * update obj ResultUtil.
     *
     * @param article
     * @return the ResultUtil
     */
    @PutMapping(value = "/update")
    public ResultUtil update(@RequestBody Article article) {
        return ResultUtil.ok("更新成功", articleService.update(article));
    }
    
     /**
     * delete obj ResultUtil.
     *
     * @param id
     * @return the ResultUtil
     */
    @DeleteMapping(value = "/del")
    public ResultUtil delById(@RequestParam("id") String id) {
        return ResultUtil.ok("删除成功", articleService.delById(id));
    }
}